package com.ruoyi.system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.system.entity.ProjectMsgTemplateDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ProjectMsgTemplateMapper extends BaseMapper<ProjectMsgTemplateDO> {

    @Select("select template_id from t_project_msg_template where project_id=#{projectId} and type=#{type} and is_active=1 and is_deleted=0 limit 1")
    Long selectActiveTemplateId(@Param("projectId") Long projectId, @Param("type") Integer type);

    @Select("select count(1) from t_project_msg_template where project_id=#{projectId} and type=#{type} and template_id=#{templateId} and is_active=1 and is_deleted=0")
    int existsActiveBinding(@Param("projectId") Long projectId, @Param("type") Integer type, @Param("templateId") Long templateId);

    @Select("select project_id from t_project_msg_template where template_id=#{templateId} and is_active=1 and is_deleted=0")
    List<Long> selectProjectIdsByTemplateId(@Param("templateId") Long templateId);
}


